<template>
  <div class="my-counter">
    <!-- 减按钮绑定 当等于1的时候就不能点击了 大于1的时候才能点击-->
    <button
      type="button"
      class="btn btn-light"
      :disabled="goods.goods_count === 1"
      @click="goods.goods_count > 1 && goods.goods_count--"
    >
      -
    </button>
    <!-- 双向绑定 输入框 当输入小于1的时候自动赋值1 -->
    <input
      type="number"
      class="form-control inp"
      v-model.number="goods.goods_count"
      @change="countChange"
    />
    <!-- 加按钮 -->
    <button type="button" class="btn btn-light" @click="goods.goods_count++">
      +
    </button>
  </div>
</template>

<script>
export default {
  props: {
    goods: Object,
  },
  methods: {
    countChange() {
      if (this.goods.goods_count < 1) {
        this.goods.goods_count = 1
      }
    }
  },
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>